package com.example.lotterysystem.common.pojo;

import com.example.lotterysystem.common.errorcode.ErrorCode;
import com.example.lotterysystem.common.errorcode.GlobalErrorCodeConstants;
import lombok.Data;
import org.springframework.util.Assert;

@Data
public class CommonResult<T> {
    private int code;

    private T data;

    private String msg;

    public static <T> CommonResult<T> success(T data){
        CommonResult<T> result=new CommonResult<>();
        result.code= GlobalErrorCodeConstants.SUCCESS.getCode();
        result.msg="";
        result.data=data;

        return result;
    }

    public static <T> CommonResult<T> error(int code,String msg){
        System.out.println(GlobalErrorCodeConstants.SUCCESS.getCode()!=code);
        Assert.isTrue(GlobalErrorCodeConstants.SUCCESS.getCode()!=code,"不是错误的错误码");
        CommonResult<T> result=new CommonResult<>();
        result.code=code;
        result.msg=msg;
        return result;
    }

 public static <T> CommonResult<T> error(ErrorCode errorCode ){

        return error(errorCode.getCode(),errorCode.getMsg());
    }



}
